#ifndef NTITLEBAR_H
#define NTITLEBAR_H
#include "solar/trunk/NinsipidView.h"
#include "solar/trunk/NWidget.h"
#include <cmath>

class NTitleBar : public QMainWindow{

    Q_OBJECT

public:
    explicit NTitleBar(QWidget *parent=nullptr);

    ~NTitleBar();

    enum ButtomType{
        Mouse_Press,
        Mouse_Release,
        Mouse_Double,
        Mouse_Move
    };

   enum BasicButtom{
        Rroof_Normal,
        Rroof_Min,
        Rroof_Max,
        Rroof_Exit
    };

   enum FillerType{
        BACKPIXMAP,
        BACKCOLOR
    };

    typedef enum {
        QUITE,
        MAXWIN,
        MINWIN,
        NORWIN
    } Type;

    typedef Type GraphType;

    void d_caption(QString text, QFont font, QColor color);

    void d_caption(QString text, QFont font);

    void d_caption(QString text);

    void d_captionico(QString curtain, NT::CST_BRIGHT_SPOT drawType=NT::DRAWTYPE_RECT, double _ico_ratio=1.2, int margins=0);

    void d_captionico(QString curtain, double _ico_ratio, int margins);

    void d_captionico(QString curtain, int margins);

    void d_caption_text_color(QMap<QString, QColor> colorOption);

    void d_basicbuttom_color(BasicButtom buttom, QMap<QString, QColor> colorOption);

    void d_basicbuttom_color(BasicButtom buttom, QString _key, QColor upcolor, bool overturn=false);

    void d_basicbuttom_pixmap(BasicButtom buttom, QString curtain);

    void d_basicbuttom_pixmap(BasicButtom buttom, QPixmap pixmap);

    void d_basicbuttom_freepixmap(GraphType Type, int graphthickness=3, QColor graphcolor=Qt::white);

    void d_basicbuttom_configur(NT::WIN_ATTRIBUTE ratioType=NT::PIXLOAD_IGNORERATIO_LOWER, NT::CST_BRIGHT_SPOT SyncdrawType=NT::DRAWTYPE_ROUND, int _rect_margins=0, double _but_ratio=1);

    void d_basicbuttom_where(BasicButtom buttom, bool enable=false);

    void d_basicbuttom_where(BasicButtom buttom, QStringList keys,  bool enable=false);

    void d_basicbuttom_where(QList<BasicButtom> buttoms, QStringList keys,  bool enable=false);

    void d_basicbuttom_where(QList<BasicButtom> buttom, bool enable=false);

    void d_systemico_configur(NT::WIN_ATTRIBUTE ratioType=NT::PIXLOAD_IGNORERATIO_LOWER, double _but_ratio=1.7);

    void d_layout_specing(uint _left_=3, uint _judge_=5, uint _right_=1);

    void d_filler_orientation(NT::CST_BRIGHT_SPOT orien);

    void d_filler_color(QList<QColor> color);

    void d_filler_color(QColor color);

    void d_filler_color(QString color);

    void d_filler_pixmap(QString curtain);

    void d_filler_enable(FillerType Type, bool Enable);

    void d_filler_clear(FillerType Type);

    void d_maskfill_transpanrent(QWidget *object, QRect winrect = QRect(), int radius=0);

    QMainWindow* piazze();

    void d_painter_effectrange(QRect _range, QList<QColor> _flrcolor={QColor(Qt::transparent)});

    void d_margin_radius(QMargins margin, int radius);

    void painterLinear(QPainter &painter, QRect offectrect, NT::CST_BRIGHT_SPOT orien, QList<QColor> _colors);

private:
    QPoint ms_start;
    int win_radius;
    int ico_margin_;
    int linear_begin;
    int linear_end;

    QColor backups_mask;
    QPixmap back_pixmap;
    QRect effect_range;
    QMap<QString, QList<QColor>> back_color_map;
    QMap<QString, bool> _switch;
    NT::CST_BRIGHT_SPOT linear_orien;
    QWidget *TT_cloakWidget = new QWidget();
    QHBoxLayout *TT_cloakHbox = new QHBoxLayout(TT_cloakWidget);
    QHBoxLayout *TT_cloakLHbox = new QHBoxLayout();
    QHBoxLayout *TT_cloakRHbox = new QHBoxLayout();
    QMainWindow *TT_piazeeWin = new QMainWindow();
    NinsipidView *TT_captionLabel = new NinsipidView(this);
    NinsipidView *TT_sysIcoLabel = new NinsipidView(this);
    NinsipidView *TT_normalLabel = new NinsipidView(this);
    NinsipidView *TT_maxwinLabel = new NinsipidView(this);
    NinsipidView *TT_minwinLabel = new NinsipidView(this);
    NinsipidView *TT_closeLabel = new NinsipidView(this);
    QMap<QString, QColor> TT_normalColorGroup;
    QMap<QString, QColor> TT_nlawinColorGroup;
    QMap<QString, QColor> TT_maxwinColorGroup;
    QMap<QString, QColor> TT_minwinColorGroup;
    QMap<QString, QColor> TT_closeColorGroup;

    QMap<FillerType,  bool> RdoMap_FillerType;

    void paintEvent(QPaintEvent *Event);

    bool eventFilter(QObject *watched, QEvent *Event);

    void notify(ButtomType Type, QPoint _pos=QPoint());

    void winmvAndstretchOff(bool enable=false);

    QPixmap freepixmap(QSize size, int graphthickness=3, QColor graphcolor=Qt::white, GraphType graphtype = Type::NORWIN);

    QPoint coord(QRect roundrect,int angle);

protected:
    MOUSE_ATTRIBUTE MSEVKEY;

signals:
    void tt_ico_pre();
    void tt_msev_pre(QPoint pos);
    void tt_msev_rls(QPoint pos);
    void tt_msev_nrrls();
    void tt_msev_etr(QEnterEvent *ev);
    void tt_msev_lev(QEvent *ev);
    void tt_msev_mv(QPoint &pos);
    void tt_cdmsev_rls(BasicButtom);
    void tt_hover_mv(QPoint &point);
    void tt_msev_db();
    void tt_ttxt_pre();
};

#endif // NTITLEBAR_H
